
# json中的dump
"""
(3). dump() : 将Python对象转化为json ,并写入JSON文件。
"""

import json

data = {
  "name": "John",
  "age": 30,
  "city": "北京",
  "is_work": False,
  "card": None
}

# 通过dump写入json文件
# with open('test_data1.json','w',encoding='utf-8') as f:
#     json.dump(data,f,ensure_ascii=False,indent=4)

# 通过write
z = json.dumps(data,ensure_ascii=False,indent=4)
with open('test_data2.json','w',encoding='utf-8') as f:
  f.write(z)